#include "comm.hpp"

int main()
{
    int shmid=Getshm();
    // cout<<shmid<<endl;
    char *shmaddr=(char*)shmat(shmid,NULL,0);
    
    // cout<<"11111"<<endl;
    int i=0;
    // while(i++<26)
    // {
    //  printf("client say@ %s\n",shmaddr);
    //  sleep(1);
    // }
        int x=mkfifo("myfifo",0664);
        if(x==-1) 
        {
            perror("myfifi error");
            return -1;
        }

        int id=open("myfifo",O_RDONLY);
        while(true)
        {
            char buffer[10];
            int n=read(id,buffer,sizeof(buffer));
            buffer[n]=0;//添加上\0 细节注意
            if(n>0)
            {
                printf("client say@ %s\n",shmaddr);
                sleep(1);
            }
            else if(n==0)
            {
                printf("通信结束\n");
                break;
            }
            else 
            {
                perror("read error");
                break;
            }
        }
     unlink("myfifo");
    shmdt(shmaddr);//进程结束，关联取消
    shmctl(shmid,IPC_CREAT,NULL);
    return 0;
}